﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long long> arr(n);
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    vector<long long> dp(n + 1, 0);
    long long ret = 0;
    for (int i = 1; i <= n; i++)
    {
        dp[i] = max(dp[i - 1] + arr[i], arr[i]);
        ret = max(ret, dp[i]);
    }
    cout << ret;
    return 0;
}